import 'package:cbec_app/components/base/base_ctr.dart';
import 'package:cbec_app/components/http/network.dart';
import 'package:get/get.dart';

class RecommendController extends BaseController {
  ///数据
  var data = {}.obs;
  //当前页码
  int page = 1;

  //是否有下一页
  var hasNextPage = false.obs;

  var goodsList = [].obs;

  var isLoading = false.obs;

  //获取个性推荐的商品列表
  Future<void> getRecommendList({String? location = ''}) async {
    if (isLoading.value) return; // 如果正在加载，则不重复请求
    isLoading.value = true; // 开始加载
    try {
      final value = await Network.getRecommendList(location: location!, page, 100);
      data.value = value;
      hasNextPage.value = value['goodsList']?['hasNextPage'] ?? false;
      goodsList.assignAll(value['goodsList']?['list'] ?? []);
    } catch (error) {
      // print("Error fetching recommendation list: $error");
    } finally {
      isLoading.value = false; // 加载完成，无论是否成功，都设置为 false
    }
  }
}
